import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/home',
    name: 'Home',
    redirect: '/welcome',
    component: Home,
    children: [{
      path: '/welcome',
      component: () => import('../components/Welcome')
    },
      {
        path: '/user',
        component: () => import('../components/sys/user')
      },
      {
        path: '/roal',
        component: () => import('../components/sys/Roal')
      },
      {
        path: '/menu',
        component: () => import('../components/sys/Menu')
      },
      {
        path: '/community',
        component: () => import('../components/dormitory/community')
      },
      {
        path: '/departments',
        component: () =>  import('../components/dormitory/Departments')
      },
      {
        path: '/MyDormitory',
        component: () => import('../components/dormitory/MyDormitory')
      },
      {
        path: '/Records',
        component: () => import('../components/dormitory/Records')
      },
      {
        path: '/MyRecord',
        component: () => import('../components/dormitory/MyRecord')
      },
      {
        path: '/attendance',
        component: () => import('../components/dormitory/Attendance')
      },
      {
        path: '/Sign',
        component: () => import('../components/sign/SignIn')
      },
      {
        path: '/SignTable',
        component: () => import('../components/sign/SignTable')
      },
      {
        path: '/MySign',
        component: () => import('../components/sign/MySign')
      },
      {
        path: '/SignList',
        component: () => import('../components/sign/SignList')
      },
      {
        path: '/discuss',
        component: () => import('../components/discuss/Discuss')
      },
      {
        path: '/deper',
        component: () => import('../components/schoolofmanagement/Departmentsclass')
      },
      {
        path: '/classmanagement',
        component: () => import('../components/schoolofmanagement/Classmanagement')
      },
      {
       path: '/apply',
        component: () => import('../components/sign/Apply')
      },
      {
        path: '/myapply',
        component: () => import('../components/sign/MyApply')
      },
      {
        path: '/score',
        component: () => import('../components/schoolofmanagement/Score')
      },
      {
        path: '/movingwater',
        component: () => import('../components/schoolofmanagement/MovingWater')
      }
    ]
  },
  {
    path: '/',
    name: "Login",
    component: () => import('../components/Login')
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeResolve((to,from,next) =>{
  if(to.path === '/') return next()
  const tokenStr = window.sessionStorage.getItem('token')
  if(!tokenStr) return next('/')
  next()
})

export default router
